****************************************************************
* Figure 1: Reading and math scores in control and treatment schools
****************************************************************
preserve
forval i = 1/5 {
	gen rcat`i' = 0 if !missing(read)
	replace rcat`i' = 1 if `i'<=read & !missing(read )
}

forval i = 6/14 {
	gen rcat`i' = 0 if !missing(read )
}

forval i = 1/5 {
	gen mcat`i' = 0 if !missing(math )
	replace mcat`i' = 1 if `i'<=math & !missing(math )
}
forval i = 6/12 {
	gen mcat`i' = 0 if !missing(math)
}

gen n = 1
collapse (mean) rcat* mcat*, by(n)
reshape long rcat mcat, i(n) j(level)

gen mlevel = level 

la def lrcat 1 "Beginner" 2 "Letter" 3 "Word" 4 "Paragraph" 5 "Story" 6 "Long text" ///
7 "News" 8 "Critical reading" 9 "Summarizing text" 10 "Textual analysis" 11 "Technical texts" ///
12 "Comprehension" 13 "Drawing inferences" 14 "Poems"
la val level lrcat 

la def lmcat 1 "Beginner" 2 "1-digit" 3 "2/3-digits" 4 "Addition/Subtraction" 5 "Multiplication/Division" ///
			 6 "Fractions/Decimals" 7 "Algorithms" 8 "Exponents" 9 "Algebra" 10 "Geometry" ///
			 11 "Trigonometry" 12 "Calculus"
la val mlevel lmcat 


twoway 	(bar rcat level, fcolor(gs10) lcolor(black)) ///
		pcarrowi 0.5 6 0.5 8 (4) "Untested" ///
				 0.75 12 0.75 14 (4) "Grade-level" ///
		, xlabel(1(1)14, valuelabel labsize(small) angle(forty_five)) ///
		xtitle(" ") legend(off) ytitle("Fraction of students") ///
		xline(6 14, lcolor(black) lw(medthick)) ylabel(, format(%9.1f))
graph export "$figs/figure1a.eps", replace 

twoway 	(bar mcat mlevel, fcolor(gs10) lcolor(black)) ///
		pcarrowi 0.5 6 0.5 8 (4) "Untested" ///
				 0.75 10 0.75 12 (4) "Grade-level" ///
		, xlabel(1(1)12, valuelabel labsize(small) angle(forty_five)) ///
		xtitle(" ") legend(off) ytitle("Fraction of students") ///
		xline(6 12, lcolor(black) lw(medthick)) ylabel(, format(%9.1f))
graph export "$figs/figure1b.eps", replace 
restore


******************************************
* Figures 2, A1, and 3
******************************************
preserve

foreach var of varlist ssc_* {
	gen pc_`var' = `var' 
}
replace pc_ssc_final = ssc_final/500 *100
egen pc_ssc_lang = rowmean(pc_ssc_english pc_ssc_tamil)

gen read3 = inrange(el_read,4,5)
gen math3 = el_math == 5
la def lread3 0 "Letters, Words" 1 "Para., Story"
la def lmath3 0 "Digits, Add/Sub." 1 "Div./Mult."
la val read3 lread3 
la val math3 lmath3


cap drop weak*
gen weak = math<=4
gen group = 1 if weak == 1 & treatment == 0
replace group = 2 if weak == 1 & treatment == 1
replace group = 3 if weak == 0 & treatment == 0
replace group = 4 if weak == 0 & treatment == 1

la def lgroup 1 "Weak, C" 2 "Weak, T" 3 "Non-Weak, C" 4 "Non-Weak, T"
la val group lgroup


*Figure 2a 
cumul pc_ssc_final, by(read3) gen(cdf_final_read)
twoway 	(line cdf_final_read pc_ssc_final if read3 == 0, sort lcolor(black) lp("...-...")) ///
		(line cdf_final_read pc_ssc_final if read3 == 1, sort lcolor(black)) ///
		, xline(35) legend(pos(6) order(1 2) rows(1) label(1 "Letters and Words") label(2 "Story and Paragraph")) ///
		xtitle("Score in AISSE Exam: Total") ytitle("CDF") ///
		xlabel(, valuelabels) xlabel(20(10)100) ylabel(, format(%9.1f))
graph export "$figs/figure2a.eps", replace

*Figure 2b
cumul pc_ssc_final, by(math3) gen(cdf_final_math)
twoway 	(line cdf_final_math pc_ssc_final if math3 == 0, sort lcolor(black) lp("...-...")) ///
		(line cdf_final_math pc_ssc_final if math3 == 1, sort lcolor(black)) ///
		, xline(35) legend(pos(6) order(1 2) rows(1) label(1 "Digits, Add./Sub.") label(2 "Mult./Div.")) ///
		xtitle("Score in AISSE Exam: Total") ytitle("CDF") ///
		xlabel(, valuelabels) xlabel(20(10)100) ylabel(, format(%9.1f))
graph export "$figs/figure2b.eps", replace 

*Figure A1a
cumul pc_ssc_lang, by(read3) gen(cdf_lang)
twoway 	(line cdf_lang pc_ssc_lang if read3 == 0, sort lcolor(black) lp("...-...")) ///
		(line cdf_lang pc_ssc_lang if read3 == 1, sort lcolor(black)) ///
		, xline(35) legend(pos(6) order(1 2) rows(1) label(1 "Letters and Words") label(2 "Story and Paragraph")) ///
		xtitle("Score in AISSE Exam: Tamil and English") ytitle("CDF") ///
		xlabel(, valuelabels) xlabel(20(10)100) ylabel(, format(%9.1f))
graph export "$figs/figurea1a.eps", replace 

*Figure A1b 
cumul pc_ssc_maths, by(math3) gen(cdf_math)
twoway 	(line cdf_math pc_ssc_math if math3 == 0, sort lcolor(black) lp("...-...")) ///
		(line cdf_math pc_ssc_math if math3 == 1, sort lcolor(black)) ///
		, xline(35) legend(pos(6) order(1 2) rows(1) label(1 "Digits, Add./Sub.") label(2 "Div./Mult.")) ///
		xtitle("Score in AISSE Exam: Maths") ytitle("CDF") ///
		xlabel(, valuelabels) xlabel(20(10)100) ylabel(, format(%9.1f))
graph export "$figs/figurea1b.eps", replace



*Figure 3
cumul pc_ssc_final, by(group) gen(cdf_final)
twoway 	(line cdf_final pc_ssc_final if group == 1, sort lcolor(black) lp("...--...")) ///
		(line cdf_final pc_ssc_final if group == 2, sort lcolor(black)) ///
		(line cdf_final pc_ssc_final if group == 3, sort lcolor(gs10) lp("...--...") ) ///
		(line cdf_final pc_ssc_final if group == 4, sort lcolor(gs10)) ///
		, xline(35) legend(pos(6) order(1 2 3 4) rows(1) label(1 "Weak, C") label(2 "Weak, T") label(3 "Non-Weak, C") label(4 "Non-Weak, T")) ///
		xtitle("Score in AISSE Exam: Total") ytitle("CDF") ///
		xlabel(, valuelabels) xlabel(20(10)100) ylabel(, format(%9.1f))
graph export "$figs/figure3.eps", replace

restore